<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <!-- 路由链接 默认为a标签 to默认为href属性 -->
        <router-link to="/user">user</router-link>
        <router-link to="/register">register</router-link>
        <!-- 路由器占位符 用来显示对应内容 -->
        <router-view></router-view>
    </div>
</body>
<script src="lib/vue_2.5.22.js"></script>
<script src="lib/vue-router_3.0.2.js"></script>

<script>
    // 1.导入Vue及VueRouter的js文件
    // 2.添加路由链接
    // 3.添加路由填充位
    // 4.定义路由组件
    // 5.配置路由规则并创建路由实例
    // 6.将路由挂载到Vue实例中
    // 注意:router-link 自带hash

    const User = {
        template: '<h1>user</h1>'
    }

    const Register = {
        template: '<h1>register</h1>'
    }

    var myrouter = new VueRouter({
        routes: [{
            path: '/user',
            component: User
        }, {
            path: '/register',
            component: Register
        }]
    })



    // 把创建的路由对象挂载到vm实例上
    var vm = new Vue({
        el: '#app',
        router: myrouter

    })
</script>

</html>